package zijie;

public class AddFunWithStr36 {
    public static void main(String [] args) {
        AddFunWithStr36 addFunWithStr36 = new AddFunWithStr36();
        String result = addFunWithStr36.addFunWithStr("1b", "2x");

        System.out.println("result = " + result);


    }
    public String addFunWithStr(String param1, String param2) {
        StringBuilder sb = new StringBuilder();
        String symbol = "0123456789abcdefghijklmnopqrstuvwxyz";
        int n = param1.length() - 1;
        int m = param2.length() - 1;
        int carry = 0;
        while (n >= 0 || m >= 0 || carry > 0){
            int a = 0;
            if(n >= 0){
                a = getData(param1.charAt(n));
            }

            int b = 0;
            if(m >= 0){
                b = getData(param2.charAt(m));
            }

            int sum = a + b + carry;
            if(sum >= 36){
                carry = sum/36;
                sum = sum % 36;
            }else{
                carry = 0;
            }
            sb.append(symbol.charAt(sum));
            n--;
            m--;
        }
        return sb.reverse().toString();

    }
    public int getData(char ch){
        if(ch > '0' && ch < '9'){
            return ch - '0';
        }else if( ch > 'a' && ch < 'z'){
            return (ch - 'a') + 10;
        }
        return -1;
    }
}
